package com.itqf.utils;

import java.util.HashMap;

/**
 * @Description: 封装一个Map的工具类，处理前端响应
 *原来：
 * Map<String , O bject> map = new HashMap<>();
 *         map.put("code",0);
 *          map.put("msg","成功");
 *         return  map;
 * JsonObject
 *
 * 通过工具类：
 *         return  R.ok("成功");
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2021/1/25
 * @Time: 下午2:45
 */
public class R  extends HashMap {
    private  int code;//状态 0 成功  1 失败
    private  String msg;//响应的信息

    public R(){}
    public  R(int code){
        super.put("code",code);
    }

    public  R(int code,String msg){
        super.put("code",code);
        super.put("msg",msg);
    }

    public  static  R  ok(){
        return new R(0);
    }
    public  static  R  ok(String msg){
        return new R(0,msg);
    }

    public  static  R  error(){
        return new R(1);
    }
    public  static  R  error(String msg){
        return new R(1,msg);
    }

    public  R put(String key,Object value){
        super.put(key,value);

        return this;
    }


}
